package com.masterclient.app.modules.shop;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.eoner.baselibrary.bean.shop.DealerStockItemBean;
import com.masterclient.app.BaseFragment;
import com.masterclient.app.R;
import com.masterclient.app.modules.shop.adapter.DealerStockAdapter;
import com.masterclient.app.modules.shop.adapter.DealerStockRecordAdapter;
import com.masterclient.app.modules.shop.contract.DealerStockContract;
import com.masterclient.app.modules.shop.contract.DealerStockPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @auther hjian
 * @date 2020/10/13.
 */
public class DealerStockFragment extends BaseFragment<DealerStockPresenter> implements DealerStockContract.View {

    @BindView(R.id.dealer_stock_root)
    LinearLayout dealerStockRoot;
    @BindView(R.id.dealer_stock_record_root)
    LinearLayout dealerStockRecordRoot;
    @BindView(R.id.dealer_stock_recycler)
    RecyclerView dealerStockRecycler;

    private int type;
    private String productId;
    private DealerStockAdapter stockAdapter;
    private DealerStockRecordAdapter stockRecordAdapter;

    public static DealerStockFragment getInstance(int type, String product_id) {
        DealerStockFragment dealerStockFragment = new DealerStockFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("type", type);
        bundle.putString("product_id",product_id);
        dealerStockFragment.setArguments(bundle);
        return dealerStockFragment;
    }

    @Override
    protected View getRootView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.fragment_dealer_stock, null);
    }

    @Override
    protected void initOnlyOnce() {
        super.initOnlyOnce();

        List<DealerStockItemBean> list = new ArrayList<>();
//        String string = "红色";
//        for (int i = 0; i < 17; i++) {
//            list.add(new DealerStockItemBean(string,"7777"+i,"77"+i,"777"+i));
//            string += "红色";
//        }

        type = getArguments().getInt("type");
        productId = getArguments().getString("product_id");

        dealerStockRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        if (type == 0){
            dealerStockRoot.setVisibility(View.VISIBLE);
            dealerStockRecordRoot.setVisibility(View.GONE);
            stockAdapter = new DealerStockAdapter();
            stockAdapter.bindToRecyclerView(dealerStockRecycler);
//            stockAdapter.setNewData(list);
            mPresenter.stockListData(productId);
        }else {
            dealerStockRoot.setVisibility(View.GONE);
            dealerStockRecordRoot.setVisibility(View.VISIBLE);
            stockRecordAdapter = new DealerStockRecordAdapter();
            stockRecordAdapter.bindToRecyclerView(dealerStockRecycler);
            stockRecordAdapter.setNewData(list);
        }


    }

    @Override
    public void showStockData(List<DealerStockItemBean> listData) {
        stockAdapter.setNewData(listData);
    }
}
